package com.zzj.ecology.admin.controller.system;

import com.zzj.ecology.admin.controller.BaseController;
import com.zzj.ecology.common.constant.UrlConstants;
import com.zzj.ecology.common.enums.BusinessType;
import com.zzj.ecology.framework.annotation.Log;
import com.zzj.ecology.framework.annotation.RepeatSubmit;
import com.zzj.ecology.system.bean.system.SysPost;
import com.zzj.ecology.system.dto.HttpResult;
import com.zzj.ecology.system.domain.Page;
import com.zzj.ecology.system.service.system.SysPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @ClassName SysPostController
 * @Description TODO
 * @Author zhijun zeng at 23:43 2020/4/9
 * @Version 1.0
 **/
@Api(value = "SysPostController", description = "岗位相关操作接口")
@RestController
public class SysPostController extends BaseController {

    @Autowired
    private SysPostService sysPostService;


    /**
     * 分页查询岗位信息数据
     * @param page
     * @return
     */
    @ApiOperation(value = "查询岗位分页数据", notes = "岗位分页数据查询", httpMethod = "POST")
    @RequestMapping(value = UrlConstants.PostUrl.LIST)
    public HttpResult findPageList(Page page) {
        HttpResult result = sysPostService.findPageList(page);
        return success(result);
    }

//    @ApiOperation(value = "", notes = "查询岗位DTree结构数据", httpMethod = "POST")
//    @RequestMapping(value = UrlConstants.PostUrl.DTREE)
//    public DTreeResponse dtree(){
//        DTreeResponse response = sysPostService.dtree();
//        return response;
//    }

    @ApiOperation(value = "查询岗位下拉数据", notes = "查询岗位下拉列表数据", httpMethod = "POST")
    @RequestMapping(value = UrlConstants.PostUrl.SELECTBOX_LIST)
    public HttpResult findPostSelectBoxList() {
        HttpResult result = sysPostService.findPostSelectBoxList();
        return success(result);
    }

    @ApiOperation(value = "查询岗位名称是否存在", notes = "查询岗位名称是否存在, 需要提供 岗位名称", httpMethod = "POST")
    @PostMapping(value = UrlConstants.PostUrl.CHECK_EXISTS)
    public String checkExists(String postName) {
        boolean b = sysPostService.checkExists(postName);
        return b ? HttpResult.SUCCESS_TAG : HttpResult.FAILURE_TAG;
    }

    @ApiOperation(value = "创建的岗位信息", notes = "创建一条新的岗位记录,岗位名称不可重复", httpMethod = "POST")
    @RepeatSubmit
    @Log(title = "岗位管理",businessType = BusinessType.INSERT)
    @PostMapping(value = UrlConstants.PostUrl.CREATE)
    public HttpResult create(SysPost sysPost) {
        System.out.println(sysPost);
        sysPost.setCreateAt(new Date());
        sysPost.setCreateBy(getUsername());
        HttpResult result = sysPostService.create(sysPost);
        return success(result);
    }

    @ApiOperation(value = "修改岗位信息", notes = "根据ID修改一条岗位记录,岗位名称不可重复", httpMethod = "POST")
    @RepeatSubmit
    @Log(title = "岗位管理",businessType = BusinessType.UPDATE)
    @PostMapping(value = UrlConstants.PostUrl.UPDATE)
    public HttpResult update(SysPost sysPost) {
        System.out.println(sysPost);
        sysPost.setUpdateAt(new Date());
        sysPost.setUpdateBy(getUsername());
        HttpResult result = sysPostService.update(sysPost);
        return success();
    }

    /**
     *  批量删除菜单数据 ,标记删除,即修改 delete_status = '0' 状态位改成 '1', 记录修改人和修改时间.
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除", notes = "批量删除岗位信息", httpMethod = "POST")
    @RepeatSubmit
    @Log(title = "岗位管理",businessType = BusinessType.DELETE)
    @PostMapping(value = UrlConstants.PostUrl.DELETE_BY_IDS)
    public HttpResult updateDeleteStatusByMenuIds(@RequestParam("ids") List<Integer> ids) {
        HttpResult result = HttpResult.error();
        if (ids.size() > 0) {
            result = sysPostService.updateDeleteStatusByIds(ids, getUsername());
        }
        return result;
    }




}
